package edos.prm.log;

import java.util.Vector;

import edos.prm.artifact.Artifact;
import edos.prm.event.Event;
import edos.prm.process.ProcessAction;
import edos.prm.task.Task;

/**
 * A {@code log} is some unit that is used to store infomation about the
 * process actions and events.
 * 
 * @author Ciaran
 */
public interface Log extends Artifact {

	/**
	 * Register the execution of a process action by a task
	 * 
	 * @param task the executing task
	 * @param action the action having been executed
	 */
	public void log(Task task, ProcessAction action);
	
	/**
	 * Register the event raised by a task.
	 * 
	 * @param task the executing task.
	 * @param event the event raised by the task.
	 */
	public void log(Task task, Event event);
	
	/**
	 * Dump the contents of the log to some output unit
	 */
	public void dump();
	
	/**
	 * A default implementation of a PRM {@code Log}
	 */
	public final static class PrmLog implements Log {
		
		private Vector<Pair<?>> log;

		public PrmLog() {
			log = new Vector<Pair<?>>();
		}

		public void log(Task task, ProcessAction action) {
			Pair<ProcessAction> pair = new Pair<ProcessAction>(task, action);
			log.add(pair);
		}

		public void log(Task task, Event event) {
			Pair<Event> pair = new Pair<Event>(task, event);
			log.add(pair);
		}
		
		public void dump() {
			for ( Pair<?> pair : log )
				System.out.println("Task " + pair.task + ": " + pair.object);
		}
		
		// Helper class
		private static class Pair<T> {
			private Task task;
			private T object;
			public Pair(Task task, T object) {
				super();
				this.task = task;
				this.object = object;
			}
		}
	}
}
